package caj.springboot.controller;

import caj.springboot.common.Result;
import caj.springboot.model.dto.log.LogInsertDTO;
import caj.springboot.model.dto.log.LogSearchDTO;
import caj.springboot.model.dto.log.LogUpdateDTO;
import caj.springboot.model.vo.LogVO;
import caj.springboot.service.LogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 日志接口层
 * @author: CAJ
 * @time: 2023/12/8 14:52
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/log")
@Api(value = "日志接口层", tags = {"日志接口层"})
public class LogController {

    private final LogService logService;

    @ApiOperation("返回所有的日志，用来测试数据库连接是否成功")
    @GetMapping("/getLogList")
    public Result<List<LogVO>> getLogList(){
        return Result.success("返回所有的日志成功",logService.getLogList());
    }

    @ApiOperation("分页获取log日志")
    @PostMapping("/getLogPage")
    public Result<IPage<LogVO>> getLogPage(@RequestBody LogSearchDTO dto){
        return Result.success("分页获取log日志成功",logService.getLogPage(dto));
    }

    @ApiOperation("插入一条log日志")
    @PostMapping("/insertLog")
    public Result<Boolean> insertLog(@RequestBody LogInsertDTO dto){
        return Result.success("插入log日志成功",logService.insertLog(dto));
    }

    @ApiOperation("修改一条log日志")
    @PostMapping("/updateLog")
    public Result<Boolean> updateLog(@RequestBody LogUpdateDTO dto){
        return Result.success("修改log日志成功",logService.updateLogById(dto));
    }

    @ApiOperation("删除一条log日志")
    @PostMapping("/deleteLog")
    public Result<Boolean> deleteLog(@RequestParam Long id){
        return Result.success("执行删除log日志操作",logService.deleteLogById(id));
    }

}
